export function isFunc(func) {
    return typeof func === "function";
}

export function loadScript(url) {
    const head = document.getElementsByTagName("head")[0];
    const script = document.createElement("script");
    script.type = "text/javascript";
    return new Promise(function(resolve, reject) {
        if (script.readyState) {
            script.onreadystatechange = function() {
                if (
                    this.readyState === "complete" ||
                    script.readyState === "loaded"
                ) {
                    script.onreadystatechange = null;
                    resolve();
                }
            };
        } else {
            script.onload = function() {
                resolve();
            };
            script.onerror = function() {
                reject(new Error("Failed to load" + url));
            };
        }
        script.src = url;
        head.appendChild(script);
    });
}
